package com.br.gpstracker;

import java.util.Arrays;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;

public class BroadcastSMSReceiver extends BroadcastReceiver {
	public static final String ACTION_SMS_SENT = "BroadcastSMSReceiver.SMS_SENT";
	public static final String ACTION_SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
	public static final String EXTRA_PDUS = "pdus";

	@Override
	public void onReceive(Context context, Intent intent) {
		Bundle bundle = intent.getExtras();

		if (intent.getAction().equals(ACTION_SMS_SENT) && bundle != null) {
			toString();
		}
		if (intent.getAction().equals(ACTION_SMS_RECEIVED) && bundle != null) {
			Object[] pdus = (Object[]) bundle.get(EXTRA_PDUS);
			SmsMessage[] msgs = new SmsMessage[pdus.length];
			for (int i = 0; i < msgs.length; i++) {
				msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
			}
			Arrays.asList(msgs);
		}
	}
}
